<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;


    protected $fillable = [
        'user_name',
        'email',
        'phone',
        'password',
    ];

    /**
     * @Author: hzwlxy
     * @Email: 120235331@qq.com
     * @Date: 2019/7/5 15:23
     * @Description: 查询时候不显示的字段
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];


    protected $casts = [
        'email_verified_at' => 'datetime',
        'phone_verified_at' => 'datetime',
    ];

     public  function  profile(){
         return $this->hasOne(UserProfile::class,"user_id");
     }


     public function  articles(){
         return $this->hasMany(Article::class);
     }

     //批量添加文章
     public  function createArticles(){
         return $this->articles()->createMany([["title"=>""],["title"=>""]]);
     }


     //第二种批量添加文章，添加模型
     public  function saveArticles(){
        return $this->articles()->saveMany([[Article::create(1)],[Article::create(2)]]);
     }

}
